package com.woniuxy.microstockserver.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.microstockserver.bean.EnterStockBean;
import com.woniuxy.microstockserver.bean.EnterStockGoodsDetailBean;
import com.woniuxy.microstockserver.bean.PageRequestBean;
import com.woniuxy.microstockserver.mapper.EnterStockGoodsDetailMapper;
import com.woniuxy.microstockserver.mapper.EnterStockMapper;
import com.woniuxy.microstockserver.service.IEnterStockService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 赵雄伟
 * 入库单impl层
 */
@Service
public class EnterStockServiceImpl implements IEnterStockService {
    @Resource
    private EnterStockMapper enterStockMapper;
    @Resource
    private EnterStockGoodsDetailMapper enterStockGoodsDetailMapper;

    @Override
    public PageInfo<EnterStockBean> findAllEnterStockBean(PageRequestBean pageRequestBean, EnterStockBean enterStockBean) {
        return  PageHelper.startPage(pageRequestBean.getPageNum(),pageRequestBean.getLimit()).
                doSelectPageInfo(()->enterStockMapper.findAllEnterStockBean(pageRequestBean, enterStockBean));
    }

    @Override
    public Long saveEnterStockBean(EnterStockBean enterStockBean) {
        enterStockMapper.saveEnterStockBean(enterStockBean);
        Long esId = enterStockBean.getId();
        return esId;
    }

    @Override
    public EnterStockBean findEnterStockAndGoodsDetail(Long id) {
        EnterStockBean enterStockBean = enterStockMapper.findEnterStockAndGoodsDetail(id);
        return enterStockBean;
    }

    @Override
    public Long upadteEnterStockBean(EnterStockBean enterStockBean) {
        Long esId = enterStockBean.getId();
        enterStockMapper.upadteEnterStockBean(enterStockBean);
        return esId;
    }
}
